/*
 * 声明泛型类
 * */
class MyCompare<U extends Comparable<U>> {
    public U getMax(U a, U b) {
        return a.compareTo(b) > 0 ? a : b;
    }
    /*public Float getMax(Float a, Float b) {
        return a.compareTo(b) > 0 ? a : b;
    }
    public Double getMax(Double a, Double b) {
        return a.compareTo(b) > 0 ? a : b;
    }
    public String getMax(String a, String b) {
        return a.compareTo(b) > 0 ? a : b;
    }*/
}

class MyAnotherCompare {
    /*
     * 声明泛型函数
     * */
    public static <T extends Comparable<T>> T getMax(T x, T y) {
        return x.compareTo(y) > 0 ? x : y;
    }
}

public class Client {
    public static void main(String[] args) {
        Integer x1 = 1, y1 = 2,rInt;
        Float x2=1.0f,y2=2.0f,rFloat;

        MyCompare<Integer> o1 = new MyCompare<Integer>();
        rInt = o1.getMax(x1, y1);
        MyCompare<Float> o2 = new MyCompare<>();
        rFloat = o2.getMax(x2, y2);
        MyCompare<String> o3 = new MyCompare<>();
        String rString = o3.getMax("China", "Chinese");

        // 使用泛型函数,编译阶段就能确定响应的动作，属于静态多态--参数多态
        Integer max1 = MyAnotherCompare.getMax(x1, y1);
        Float max2 = MyAnotherCompare.getMax(x2, y2);
        String max3 = MyAnotherCompare.getMax("China", "Chinese");
//        MyCompare<int> myCompare = new MyCompare<int>();
    }
}
